package com.tj.seed.common.swagger;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@Configuration
public class SwaggerConfig {
    @Bean
    public Docket initDocket(Environment env) {
        //设置要暴露的接口文档的配置环境
        Profiles profiles = Profiles.of("dev", "qa");
        boolean flag = env.acceptsProfiles(profiles);
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo()) //配置显示文档的title,整体描述、版本等
                .enable(flag)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.tj.seed"))//过滤芯哪些api显示出来
                .paths(PathSelectors.any())//这里可以用regex()方法指定哪些url路径暴露
                .build();//这里可以统一添加前缀

    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("TJ-Seed接口文档")
                .description("技术支持-TJ")
                .contact(new Contact("TJ", "http://www.tj.com", "titlezhang@163.com"))
                .version("1.0.0")
                .build();
    }
}
